package dS.ProjectGPS.LeicaOWI;

import javax.microedition.lcdui.*;

public class FormOwi1SP_HT extends Form implements FormOwi {
  OWIAgent owiAgent = null;

  TextField p3 = new TextField("Parameter #1", "", 50, TextField.DECIMAL);
  TextField p2 = new TextField("Parameter #2", "", 50, TextField.DECIMAL);
  TextField p1 = new TextField("Parameter #3", "", 50, TextField.DECIMAL);
  TextField originY = new TextField("Origin X0 (m)", "", 50, TextField.DECIMAL);
  TextField originX = new TextField("Origin Y0 (m)", "", 50, TextField.DECIMAL);

  public FormOwi1SP_HT(OWIAgent o) {
    super("Height Transformation");

    owiAgent = o;

    try {
      ndsInit();
    }
    catch (Exception ex) {
    }
  }

  public void ndsInit() throws Exception {
    append(originX);
    append(originY);
    append(p1);
    append(p2);
    append(p3);
  }

  public void update() {
    owiAgent.query(OWI.qs1SP());

    originX.setString(OWI.ospHtOriginX);
    originY.setString(OWI.ospHtOriginY);
    p1.setString(OWI.ospHtP1);
    p2.setString(OWI.ospHtP2);
    p3.setString(OWI.ospHtP3);
  }

  public void save() {

    String msgId = "1SP";

    // Setup SET parameters
    String[] outputs = {
                   msgId,
                   OWI.ospUtmFOEast,
                   OWI.ospUtmFONorth,
                   OWI.ospUtmLatOrigin,
                   OWI.ospUtmCentralMeridian,
                   OWI.ospUtmScale,

                   OWI.osp2dhRotX,
                   OWI.osp2dhRotY,
                   OWI.osp2dhShiftX,
                   OWI.osp2dhShiftY,
                   OWI.osp2dhRotation,
                   OWI.osp2dhScale,

                   originX.getString(),
                   originY.getString(),
                   p1.getString(),
                   p2.getString(),
                   p3.getString()

    };

    //Send message and update form if successful
    int ackCode = (owiAgent.set(msgId, OWI.setMessage(outputs)));
    Controller.showACKAlert(this,this,ackCode);

  }

}
